# Copyright (c) 2024 iSOFT INFRASTRUCTURE SOFTWARE CO., LTD.
# easyAda is licensed under Mulan PubL v2.
# You can use this software according to the terms and conditions of the Mulan PubL v2.
# You may obtain a copy of Mulan PubL v2 at:
#          http://license.coscl.org.cn/MulanPubL-2.0
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PubL v2 for more details.

CFLAGS += -fasm -ffreestanding -ffunction-sections -fdata-sections -Wall -nostdinc -g -Wno-unused-function
LDFLAGS := -nostdlib

CROSS_COMPILE ?= aarch64-none-elf-
CC := ${CROSS_COMPILE}gcc
LD := ${CROSS_COMPILE}ld
AR := ${CROSS_COMPILE}ar
OBJCOPY := ${CROSS_COMPILE}objcopy
OBJDUMP := ${CROSS_COMPILE}objdump

# parse config
ifneq (,$(wildcard $(CONFIG_DIR)/.config))
    include $(CONFIG_DIR)/.config

    ifeq ($(CONFIG_DEBUG_BUILD),y)
        CFLAGS += -g
    endif

    ifeq ($(CONFIG_ARCH_ARM64),y)
      ARCH := arm64
    else
      $(warning "Unsupported Archtecture!")
    endif

    # platform
    ifeq ($(CONFIG_PLAT_G9X),y)
      PLAT := g9x
      OFORMAT := elf64-littleaarch64
    else ifeq ($(CONFIG_PLAT_RPI4B),y)
      PLAT := rpi4b
      OFORMAT := elf64-littleaarch64
    else ifeq ($(CONFIG_PLAT_QEMU_VIRT),y)
      PLAT := qemu_virt
      OFORMAT := elf64-littleaarch64
    else ifeq ($(CONFIG_PLAT_BLACKSESAME),y)
      PLAT := blacksesame
      OFORMAT := elf64-littleaarch64
    else
      $(warning "Unsupported Platform!")
    endif
endif # include .config

export CC
export LD
export AR
export OBJDUMP
export OBJCOPY
export CFLAGS
export LDFLAGS
export ARCH
export PLAT
export OFORMAT
export CFLAGS
